using System;
using System.Windows;
using System.Windows.Controls;
namespace MicroMsg.UI.UserContrl
{
	public class AutoSizePanel : Panel
	{
		protected override Size MeasureOverride(Size availableSize)
		{
			if (base.get_Children().get_Count() < 2)
			{
				return base.MeasureOverride(availableSize);
			}
			base.get_Children().get_Item(1).Measure(availableSize);
			base.get_Children().get_Item(0).Measure(new Size(base.get_Children().get_Item(1).get_DesiredSize().get_Width(), base.get_Children().get_Item(1).get_DesiredSize().get_Height()));
			for (int i = 2; i < base.get_Children().get_Count(); i++)
			{
				base.get_Children().get_Item(i).Measure(availableSize);
			}
			return new Size(base.get_Children().get_Item(1).get_DesiredSize().get_Width(), base.get_Children().get_Item(1).get_DesiredSize().get_Height());
		}
		protected override Size ArrangeOverride(Size finalSize)
		{
			if (base.get_Children().get_Count() < 2)
			{
				return base.ArrangeOverride(finalSize);
			}
			for (int i = 0; i < base.get_Children().get_Count(); i++)
			{
				double width = base.get_Children().get_Item(1).get_DesiredSize().get_Width();
				double height = base.get_Children().get_Item(1).get_DesiredSize().get_Height();
				base.get_Children().get_Item(i).Arrange(new Rect(0.0, 0.0, width, height));
			}
			return new Size(base.get_Children().get_Item(1).get_DesiredSize().get_Width(), base.get_Children().get_Item(1).get_DesiredSize().get_Height());
		}
	}
}
